package sketch.specs;

import java.util.List;
import java.util.Map;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

import sketch.ast.ASTUtils;
import sketch.util.Checker;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class DeclaredValuesFinderTest extends TestCase {
	public static Test suite() {
        return new TestSuite(DeclaredValuesFinderTest.class);
    }
	
	public void testGetAllValueDeclarations() {
//		String filePath = "./tests/sketch/specs/samplecode.txt";
		String filePath = "./testfiles/sketch/specs/SampleCode.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		List<MethodDeclaration> methods = ASTUtils.getMethodsWithAnnotation(unit, "TestSketch");
		//get the comment list
		List<Comment> cs = unit.getCommentList();
		//unit.getLineNumber(position)
		//cs = ASTUtils.blockComments(cs);
		for(MethodDeclaration method : methods) {
			System.out.println("  ---- processing method to see the value declaration: " + method.getName() + " ---- ");
			BlockMappingVisitor visitor = new BlockMappingVisitor(cs);
			visitor.visit(method);
			Map<Block, Comment> blockCommentMappings = visitor.getBlockMappings();
			for(Block block : blockCommentMappings.keySet()) {
				SpecValueDeclarationFinder finder = new SpecValueDeclarationFinder(block);
				List<VariableDeclarationStatement> varDecls = finder.getAllValueDeclaredStatements();
				for(VariableDeclarationStatement varDecl : varDecls) {
					System.out.println("  " + varDecl);
				}
				System.out.println(block);
			}
		}
	}
	
}
